
package com.xbongbong.sys.domain.entity;

import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.Entity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Objects;

/**
 * @author kaka
 * @since old version
 * @time 2018-8-28
 */
@Setter
@Getter
@ToString
public class FeeCompanyEntity extends Entity {

	private static final long serialVersionUID = -1L;

	public FeeCompanyEntity(){
		this.updateTime = DateUtil.getInt();
		this.feeType = 0;
		this.fee = 0F;
		this.del = 0;
	}

	public FeeCompanyEntity(boolean isUpgradeRenewal){
		this.userNumDingding = 0;
		this.marketBuyJson = "";
		this.authChannel = "";
		this.expressCode = "";
		this.expressInfo = "";
		this.feeDingding = 0F;
		this.invoiceInfo = "";
		this.opUserName = "";
		this.updateTime = DateUtil.getInt();
		this.addTime = DateUtil.getInt();
		this.orderId = "";
		this.buyNum = 1;
		this.drp = "";
		this.del = 0;

		this.feeType = 0;
		this.isInvoice = 0;
		this.payTime = DateTimeUtil.getInt();
		this.status = 0;
		this.isPay = 1;
		this.isActive = 1;

	}
	//========== properties ==========

    /**
     * 主键
     */
	private Integer id;
    /**
     * 企业id
     */
	private String corpid;
    /**
     * 公司名
     */
	private String corpName;
    /**
     * 套餐id
     */
	private Integer feeId;
    /**
     * 套餐名
     */
	private String feeName;
    /**
     * 实际售价
     */
	private Float realPrice;
    /**
     * 购买套餐数量
     */
	private Integer buyNum;
    /**
     * 套餐费用
     */
	private Float fee;
    /**
     * 0公司总人数套餐  1实际使用人数套餐
     */
	private Integer feeType;

	private Integer userNum;

	private Integer dayNum;

	private Long payTime;

	private Long startTime;

	private Long endTime;
    /**
     * 是否已支付，0未支付，1支付，特别注意，免费体验套餐要标为未支付0，用来区别收费套餐
     */
	private Integer isPay;
    /**
     * 是否生效，0不生效，1已生效，2失效，付费后，免费套餐要标记为2失效
     */
	private Integer isActive;
    /**
     * 是否开发票 0不开发票， 1待开发票,2已申请开发票
     */
	private Integer isInvoice;
    /**
     * 主企业
     */
	private String mainCorpid;
    /**
     * 购买套餐操作人[对方]
     */
	private String opUserName;
    /**
     * 创建时间
     */
	private Integer addTime;
    /**
     * 更新时间
     */
	private Integer updateTime;
    /**
     * 删除标记
     */
	private Integer del;
	private Integer payType;
	private String memo;
	private String orderId;
    /**
     * 渠道码
     */
	private String authChannel;
    /**
     * 发票信息，json
     */
	private String invoiceInfo;
    /**
     * 快递收件人信息，json
     */
	private String expressInfo;
    /**
     * 快递单号
     */
	private String expressCode;
    /**
     * 状态，0用户提交等待开票，1已开票，2已邮寄，3取消
     */
	private Integer status;

	private String saleName;
	private Integer orderType;
	private String marketBuyJson;
	private String drp;
	private Float feeDingding;
	private Float feeInvoice;
	private Integer userNumDingding;
	/**
	 * 服务停止时间
	 */
	private Long serviceStopTime;
	/**
	 * 退款状态
	 */
	private Integer refundStatus;
	/**
	 * 退款时间
	 */
	private Integer refundTime;
	/**
	 * 退款金额
	 */
	private Float refundAmount;


	public void addMarketBuyJson(String marketBuyJson) {
		if(StringUtil.isEmpty(this.marketBuyJson)) {
			this.marketBuyJson = marketBuyJson;
		}else {
			this.marketBuyJson = this.marketBuyJson + marketBuyJson;
		}
	}

	/**
	 * 获取开票金额
	 * @param fee 付费金额
	 * @param distributorCorpId 公司id
	 * @param drp 是否drp
	 * @return
	 * 创建时间： 2018-6-8 下午7:26:15
	 * 修改时间： 2018-6-8 下午7:26:15 chy
	 * @author chy
	 * @since v3.23
	 * @version v3.23
	 */
	public static Float getFeeInvoice(Float fee, String distributorCorpId, String drp) {
		/**
		 * 渠道（非drp，且非我们自己公司分销的）
		 */
		//drp不为空("DRP"、"ALIYUN_DEAL")即可
		if(!StringUtil.isEmpty(drp) && !Objects.equals(distributorCorpId, "dinge3fa697f86d461d2")){
			//渠道出货价是30%
			return fee*0.3f;
		}
		//其他销售是原价
		return fee;
	}

}

